﻿Imports System.Activities.Presentation.Model
Imports System.Activities
Imports Microsoft.VisualBasic.Activities
Imports System.Activities.Expressions

''' <summary>Enum 変換用 Converter</summary>
Public Class EnumBooleanConverter
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If (value Is Nothing) OrElse (parameter Is Nothing) Then Return False

        If Not [Enum].IsDefined(value.GetType, value) Then Return False

        Dim inputValue = [Enum].Parse(value.GetType, parameter.ToString)
        Return (inputValue = value)
    End Function

    Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        If (value Is Nothing) OrElse (parameter Is Nothing) Then Return Nothing

        Dim useValue = CType(value, Boolean)
        Dim targetValue = parameter.ToString
        If useValue Then Return [Enum].Parse(targetType, targetValue)
        Return Nothing
    End Function

End Class
